package com.leetcode.LC;

public class LC682 {
    public int calPoints(String[] ops) {


        int[] ints = new int[ops.length];
        int k=0;
        for (int i = 0; i < ops.length; i++) {
            if (isNum(ops[i])) {
                ints[k] = Integer.valueOf(ops[i]);
                k++;
            } else if (ops[i].equals("+")) {
                ints[k] = ints[k - 1] + ints[k - 2];
                k++;
            } else if (ops[i].equals("D")) {
                ints[k] = ints[k - 1] * 2;
                k++;
            } else if (ops[i].equals("C")) {
                k--;
                ints[k] = 0;
            }

            for (int anInt : ints) {
                System.out.print(anInt+",");
            }
            System.out.println();
        }
        int sum = 0;
        for (int anInt : ints) {
            sum += anInt;
        }
        return sum;
    }

    public boolean isNum(String str) {
        for (int i = 0; i < str.length(); i++) {
            if ((str.charAt(i) < '0' || str.charAt(i) > '9')&&str.charAt(i)!='-') {
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        System.out.println(new LC682().calPoints(new String[]{"36","28","70","65","C","+","33","-46","84","C"}));
    }
}
